package math;
import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.analysis.integration.*;

public class IntegralExample {
    public static void main(String[] args) {
        class Sin implements UnivariateFunction{
            private int xs;
            public Sin(int xs){
                this.xs = xs;
            }

            public double value(double x) {
                return xs * Math.sin(x);
            }
        }
//        UnivariateFunction f = new UnivariateFunction() {
//            public double value(double x) {
//                return Math.sin(x);
//            }
//        };
        Sin f = new Sin(2);

        UnivariateIntegrator integrator = new SimpsonIntegrator();
        double result = integrator.integrate(1000, f, 0, Math.PI);
        System.out.println("The integral value is: " + result);
    }
}
